#include "stdafx.h"
#include "Basket.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CBasket::CBasket(void):m_Bitmap(NULL)
{
	m_Bitmap = new CCBitmap(_BASKET);
	m_Cx = BASKET_X;
	m_Cy = BASKET_Y;
}


CBasket::~CBasket(void)
{
	m_Bitmap->m_Bitmap.DeleteObject();
	delete m_Bitmap;
}
void CBasket::Draw(CDC *pDC)
{	
	CDC dcMem;
	dcMem.CreateCompatibleDC (pDC);
	dcMem.SelectObject(&m_Bitmap->m_Bitmap);
	pDC->StretchBlt(m_Cx,m_Cy,BASKET_WIDTH,BASKET_HEIGHT,&dcMem,0,0,m_Bitmap->m_bmWidth,m_Bitmap->m_bmHeight,SRCCOPY);
	dcMem.DeleteDC();

	//CDC memDC;
	//memDC.CreateCompatibleDC(pDC);
	//memDC.SelectObject(&m_Bitmap->m_Bitmap);
	//// set transparent
 //   // create mask
 //   CDC* dcMask = new CDC();
 //   CBitmap* bmMask = new CBitmap();
 //   dcMask->CreateCompatibleDC(pDC);
 //   bmMask->CreateBitmap(BASKET_WIDTH,BASKET_HEIGHT,1,1,0 );
 //   dcMask->SelectObject(&bmMask);
	//dcMask->StretchBlt(m_Cx,m_Cy,BASKET_WIDTH,BASKET_HEIGHT,&memDC,0,0,m_Bitmap->m_bmWidth,m_Bitmap->m_bmHeight,SRCCOPY);
	//pDC->StretchBlt(m_Cx,m_Cy,BASKET_WIDTH,BASKET_HEIGHT,dcMask,0,0,m_Bitmap->m_bmWidth,m_Bitmap->m_bmHeight,SRCPAINT);
	//pDC->StretchBlt(m_Cx,m_Cy,BASKET_WIDTH,BASKET_HEIGHT,&memDC,0,0,m_Bitmap->m_bmWidth,m_Bitmap->m_bmHeight,SRCAND);

	//bmMask->DeleteObject();
	//dcMask->DeleteDC();
	//memDC.DeleteDC();
}

void CBasket::Basket_Move_Right()
{
	if(m_Cx + BASKET_OFFSET_MOVE <((GM_RIGHT-10) - BASKET_WIDTH))
	{
		m_Cx += BASKET_OFFSET_MOVE;
	}
}

void CBasket::Basket_Move_Left()
{
	if(m_Cx - BASKET_OFFSET_MOVE > GM_LEFT)
	{
		m_Cx -=BASKET_OFFSET_MOVE ;
	}
}

int CBasket::Basket_Move(int Offset_Move)
{
	if(m_Cx + Offset_Move > GM_LEFT & m_Cx + Offset_Move < ((GM_RIGHT-10) - BASKET_WIDTH))
	{
		m_Cx += Offset_Move;
		return 1;
	}
	return 0;
}

int CBasket::Get_x()
{
	return m_Cx;
}